package util;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;

public class GeradorArquivo {
	
	public static void escreveArquivoCDF(List<Double> data) {
		try {
			FileWriter fstream = new FileWriter("saida.txt");
			BufferedWriter out = new BufferedWriter(fstream);
			
			Collections.sort(data);
			
			/*Map<Double, Double> map = new TreeMap<Double, Double>();
			
			for(int i = 1; i <= data.size(); i++) {
				map.put(data.get(i - 1), i*1.0/data.size()*1.0);
			}
			
			for(Entry<Double, Double> e : map.entrySet()) {
				out.write(e.getKey().toString().replace(".", ",") + "\t" + e.getValue().toString().replace(".", ",") + "\n");
				
			}*/
			
			SortedMap<Double, Double> map = new TreeMap<Double, Double>();
			for(int i = 1; i <= data.size(); i++) {
				map.put(data.get(i - 1), i*1.0/data.size()*1.0);
			}
			
			for(Entry<Double, Double> e : map.entrySet()) {
				out.write(e.getKey().toString().replace(".", ",") + "\t" + e.getValue().toString().replace(".", ",") + "\n");
				
			}
			
			out.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
